﻿using System.Collections.Generic;
using Journal.Domain.IDomainServices;
using Journal.Domain.Models;
using Journal.Front.Presentation.Models.StudyGroupModels;
using Journal.Front.Presentation.PresentationServicesInterfaces;

namespace Journal.Front.Presentation.PresentationServices
{
    public class StudyGroupPresentationService : IStudyGroupPresentationService
    {
        private readonly IStudyGroupDomainService studyGroupDomainService;
        private readonly IEducationInstitutionDomainService educationInstitutionDomainService;

        public StudyGroupPresentationService(IStudyGroupDomainService studyGroupDomainService, IEducationInstitutionDomainService educationInstitutionDomainService)
        {
            this.studyGroupDomainService = studyGroupDomainService;
            this.educationInstitutionDomainService = educationInstitutionDomainService;
        }

        public StudyGroupSelectModel GetStudyGroupSelectModel(int userId, bool? isAll)
        {
            IList<StudyGroup> names;
            if(isAll.HasValue)
            {
                int educationInstitutionId = educationInstitutionDomainService.GetEducationInstitutionIdByUserId(userId);
                names = studyGroupDomainService.GetAllStudyGroupByEducationInstitutionId(educationInstitutionId);
            }
            else
            {
                names = studyGroupDomainService.GetStudyGroupsByUserId(userId);
            }

            return new StudyGroupSelectModel(names);
        }
    }
}